<template>
  <div class="login-wrrap">
    <div class="form-layout">
      <el-form :model="formObj" ref="formObj" label-width="80px" class="formObj" :rules="rules">
        <el-form-item label="用户名" prop="username">
          <el-input type="text" v-model.number="formObj.username" clearable autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model.number="formObj.password" clearable autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('formObj')">提交</el-button>
          <el-button @click="resetForm('formObj')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import { encryption } from "@/utils/jsencryt.js";
import { loginApi } from "@/api/login/index.js";
import qs from "qs";

export default {
  name: "Login",
  data() {
    return {
      formObj: {
        username: "",
        password: ""
      },
      rules: {
        username: [
          {
            required: true,
            message: "请输入账号",
            trigger: "blur"
          }
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.handleLogin();
        } else {
          this.$message({
            showClose: true,
            message: "登录有误请重新登录",
            type: "error"
          });
        }
      });
    },
    async handleLogin() {
      this.formObj.password =
        "PJhOBWDv7hlJ0RKDfAfooPrOSMr40oKlIuWzsfEuirNGcayFWQ/fttm2PrILtW10f6sb2LV3T/BC+lUvG8dpLqFu1SGgdalszUvglKG6Vdzl1f3feUIOvO4gWtFObbbLFhKZIsxotzul0iGAz2Uk7gXTlaXlH4+3GXSJYAK9Qjg=";
      const res = await loginApi(qs.stringify(this.formObj));
      if (res.code == "200") {
        this.$message({
          showClose: true,
          message: "登录成功",
          type: "success"
        });
        localStorage.setItem("token", res.jwtToken);
      } else {
        this.$message({
          showClose: true,
          message: "登录有误请重新登录",
          type: "error"
        });
      }
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {},
  mounted() {}
};
</script> 

<style lang="scss" >
.login-wrrap {
  background-color: $blue !important;
  position: relative;
  color: #fff;
  height: 100%;
  .form-layout {
    width: 400px;
    height: 260px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 35px 35px 15px 35px;
    .formObj {
      color: #fff;
    }
  }
}
</style>


